class Event {
  on(event, fn) {
    if (typeof fn != "function") {
      return
    }
    this._cbs = this._cbs || {};
    (this._cbs[event] = this._cbs[event] || []).push(fn)
  }
  emit(event) {
    this._cbs = this._cbs || {}
    var callbacks = this._cbs[event], args
    if (callbacks) {
      callbacks = callbacks.slice(0)
      args = [].slice.call(arguments, 1)
      for (var i = 0, len = callbacks.length; i < len; i++) {
        callbacks[i].apply(null, args)
      }
    }
  }
 off(event, fn) {
    this._cbs = this._cbs || {}
    if (!arguments.length) {
      this._cbs = {}
      return
    }
    var callbacks = this._cbs[event]
    if (!callbacks) return
    if (arguments.length === 1) {
      delete this._cbs[event]
      return
    }
    var cb
    for (var i = 0, len = callbacks.length; i < len; i++) {
      cb = callbacks[i]
      if (cb === fn || cb.fn === fn) {
        callbacks.splice(i, 1)
        break
      }
    }
    return
  }
}
export default Event